package com.example.myapplication.adapter.recyclerViewAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.activity.LoadingActivity;
import com.example.myapplication.R;
import com.example.myapplication.entity.PlayList;

import java.util.List;

public class MineIndexAdapter extends RecyclerView.Adapter<MineIndexAdapter.MineIndexHolder> {
    private Context context;
    private List<PlayList> playlistBeanList;
    private MineIndexHorAdapter adapter;
    private int count=0;

    public void setData( List<PlayList> playlistBeanList){
        this.playlistBeanList = playlistBeanList;
        count++;
        notifyDataSetChanged();
    }

    public MineIndexAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public MineIndexHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dj_adapter,parent,false);
        return new MineIndexHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MineIndexHolder holder, int position) {
         if(position==0) {
             holder.dj_recommend.setText(LoadingActivity.profileBean.getNickname()+" 收藏的歌单");
         }
         else{
             holder.dj_recommend.setText("为你推荐");
         }

    }

    @Override
    public int getItemCount() {
        return count;
    }

    class  MineIndexHolder extends RecyclerView.ViewHolder {
        RecyclerView recycle_view_dj;
        TextView dj_recommend;
        public MineIndexHolder(@NonNull View itemView) {
            super(itemView);
            recycle_view_dj = itemView.findViewById(R.id.recycle_view_dj);
            dj_recommend = itemView.findViewById(R.id.dj_recommend);
            RecyclerView.LayoutManager manager_hor= new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false);
            recycle_view_dj.setLayoutManager(manager_hor);
            adapter = new MineIndexHorAdapter();
            recycle_view_dj.setAdapter(adapter);
            adapter.setData(playlistBeanList,context);
        }
    }
}
